﻿/*
 * Class  :  LibGlobal
 * Author : Chung Thành Phước 
 * Create Date: 11/12/2014
 * Update date: 11-12-2014 by Chung Thành Phước 
 * Reference: System.IO,System.Web,System.Web.UI
 */

using System.IO;
using System.Web;
using System.Web.UI;
namespace LibGlobal
{
    public class Report
    {
        /*
        * _fileName     :  tên tập tin
        * _gridControl  : lưới hiễn thị
        * _titile       :  tiêu đề hiễn thị trên báo cáo
        * DateBegin     :  từ ngày
        * DateEnd       :  đến ngày
        */
        public static void ExportGridToExcel(string _fileName, string _sheetName, Control _gridControl, string _titile, string _dateBegin, string _dateEnd)
        {
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + _fileName + ".xls");
            HttpContext.Current.Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
            HttpContext.Current.Response.Write("<head>");
            HttpContext.Current.Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">");
            HttpContext.Current.Response.Write("<!--[if gte mso 9]>");
            HttpContext.Current.Response.Write("<xml>");
            HttpContext.Current.Response.Write("<x:ExcelWorkbook>");
            HttpContext.Current.Response.Write("<x:ExcelWorksheets>");
            HttpContext.Current.Response.Write("<x:ExcelWorksheet>");
            //this line names the worksheet
            HttpContext.Current.Response.Write("<x:Name>" + _sheetName + "</x:Name>");//Tên Sheet
            HttpContext.Current.Response.Write("<x:WorksheetOptions>");
            //these 2 lines are what works the magic
            HttpContext.Current.Response.Write("<x:Panes>");
            HttpContext.Current.Response.Write("</x:Panes>");
            HttpContext.Current.Response.Write("</x:WorksheetOptions>");
            HttpContext.Current.Response.Write("</x:ExcelWorksheet>");
            HttpContext.Current.Response.Write("</x:ExcelWorksheets>");
            HttpContext.Current.Response.Write("</x:ExcelWorkbook>");
            HttpContext.Current.Response.Write("</xml>");
            HttpContext.Current.Response.Write("<![endif]-->");
            HttpContext.Current.Response.Write("</head>");
            HttpContext.Current.Response.Write("<body>");
            /*--Cấu hình Template--*/
            HttpContext.Current.Response.Write("<table style='width: 100%;text-align: center;font-size: 14px;font-family: Times New Roman'>");
            HttpContext.Current.Response.Write("<thead>");
            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<th></th>");
            HttpContext.Current.Response.Write("<th style='font-size: 20pt;font-weight: bold;'>" + _titile + "</th>");
            HttpContext.Current.Response.Write("<th></th>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write(
                "<td colspan='3' style='text-align: center;font-weight: bold;padding: 8px'></td>");
            HttpContext.Current.Response.Write("</tr>");
            HttpContext.Current.Response.Write("</thead>");

            HttpContext.Current.Response.Write("<tbody>");
            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write(
                "<td colspan='3' style='text-align: center;font-weight: 500;padding: 8px'>Từ ngày: " + _dateBegin + " đến ngày: " + _dateEnd + " </td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write(
                "<td colspan='3' style='text-align: center;font-weight: bold;padding: 8px'></td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td colspan='3' style='text-align: center;'>");
            var sw = new StringWriter();
            var hw = new HtmlTextWriter(sw);
            _gridControl.RenderControl(hw);
            HttpContext.Current.Response.Output.Write(sw.ToString());
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write(
                "<td colspan='3' style='text-align: center;font-weight: bold;padding: 8px'></td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='text-align: center;'>Tp.HCM, ngày …. tháng …. Năm</td>");
            HttpContext.Current.Response.Write("<td></td>");
            HttpContext.Current.Response.Write("<td style='text-align: center;'>Tp.HCM, ngày …. tháng …. Năm …….</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write(
                "<td colspan='3' style='text-align: center;font-weight: bold;padding: 8px'></td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='text-align: center;font-weight: bold'>Kế toán trưởng</td>");
            HttpContext.Current.Response.Write("<td></td>");
            HttpContext.Current.Response.Write("<td style='text-align: center;font-weight: bold'>Giám đốc</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write(
                "<td colspan='3' style='text-align: center;font-weight: bold;padding: 8px'></td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='text-align: center;'>(ký, họ tên)</td>");
            HttpContext.Current.Response.Write("<td></td>");
            HttpContext.Current.Response.Write("<td style='text-align: center;'>(ký, họ tên, đóng dấu)</td>");
            HttpContext.Current.Response.Write("</tr>");
            HttpContext.Current.Response.Write("</tbody></table>");
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
            /*--End--*/
            HttpContext.Current.Response.Write("</body>");
            HttpContext.Current.Response.Write("</html>");
        }

        public static void ExportReceipt(string _fileName, string _sheetName, string _titile, string _companyName,
            string _addressName, string _payerRecipientCode, string _addressPayerRecipient, string _reasonRecipient,string _amount,string _amountText,
            string _VoucherAmount, string _date, string _month, string _year)
        {
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + _fileName + ".xls");
            HttpContext.Current.Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
            HttpContext.Current.Response.Write("<head>");
            HttpContext.Current.Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">");
            HttpContext.Current.Response.Write("<!--[if gte mso 9]>");
            HttpContext.Current.Response.Write("<xml>");
            HttpContext.Current.Response.Write("<x:ExcelWorkbook>");
            HttpContext.Current.Response.Write("<x:ExcelWorksheets>");
            HttpContext.Current.Response.Write("<x:ExcelWorksheet>");
            //this line names the worksheet
            HttpContext.Current.Response.Write("<x:Name>" + _sheetName + "</x:Name>"); //Tên Sheet
            HttpContext.Current.Response.Write("<x:WorksheetOptions>");
            //these 2 lines are what works the magic
            HttpContext.Current.Response.Write("<x:Panes>");
            HttpContext.Current.Response.Write("</x:Panes>");
            HttpContext.Current.Response.Write("</x:WorksheetOptions>");
            HttpContext.Current.Response.Write("</x:ExcelWorksheet>");
            HttpContext.Current.Response.Write("</x:ExcelWorksheets>");
            HttpContext.Current.Response.Write("</x:ExcelWorkbook>");
            HttpContext.Current.Response.Write("</xml>");
            HttpContext.Current.Response.Write("<![endif]-->");
            HttpContext.Current.Response.Write("</head>");
            HttpContext.Current.Response.Write("<body>");
            /*--Cấu hình Template--*/
            HttpContext.Current.Response.Write(
                "<table style=\"width: 100%;font-family: Times New Roman;border: 2px solid #000080\">");
            /*---------------Header---------------*/
            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write(
                "<td style='text-align: left;padding: 5px;width: 30%;vertical-align: middle'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Đơn vị : " + _companyName +
                                               " </p>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Địa chỉ : " +
                                               _addressName + " </p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write(
                "<td style='text-align: center;width: 40%;font-family: Times New Roman;font-weight: bold;font-size: 24px;vertical-align: middle'>");
            HttpContext.Current.Response.Write(_titile);
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write(
                "<td style='text-align: left;width: 10%;margin-left: 8px;vertical-align: middle'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Số : </p>");
            HttpContext.Current.Response.Write("</td>");


            HttpContext.Current.Response.Write(
                "<td style='text-align: center;width: 20%;margin-left: 8px;vertical-align: middle'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Mã số : 02 - TT</p>");
            HttpContext.Current.Response.Write(
                "<p style='margin:5px 5px 0 0;font-size: 12px'>(Ban hành theo QĐ số 15/2006/QĐ-BTC)</p>");
            HttpContext.Current.Response.Write(
                " <p style='margin:5px 5px 0 0;font-size: 12px;font-style: italic'>(ngày 20/03/2006 của Bộ Trưởng BTC)</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write("<span>Ngày " + _date + " tháng " + _month + " năm " + _year + "</span><br/>");
            HttpContext.Current.Response.Write("<span>Quyển số : ......</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Nợ : " +_VoucherAmount+" </p>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Có : " + _amount + "</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td colspan='4' style='height: 20px'>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");
            /*---------------End---------------*/

            /*--------Nội dung Export---------*/
            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Họ tên người nộp tiền :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _payerRecipientCode + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Địa chỉ :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _addressPayerRecipient + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Lý do thu :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _reasonRecipient + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Số tiền :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px;text-align: left'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _amount + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px;text-align: left'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Số tiền bằng chử :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _amountText + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");
            /*---------------End--------------*/

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td colspan='4' style='height: 20px'>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            /*--------------Footer------------*/
            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write("<span style='margin-left: 150px;font-weight: 600'>Giám đốc</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write("<span style='margin-left: 150px;font-weight: 600'>Kế toán trưởng</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write("<span style='margin-left: 150px;font-weight: 600'>Thủ quỹ</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 150px;font-weight: 600'>Người lập phiếu</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 113px;font-weight: 400;font-style: italic'>(Ký,họ tên,đóng dấu)</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 87px;font-weight: 400;font-style: italic'>(Ký,họ tên,đóng dấu)</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 103px;font-weight: 400;font-style: italic'>(Ký,họ tên,đóng dấu)</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 99px;font-weight: 400;font-style: italic'>(Ký,họ tên,đóng dấu)</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("</tr>");
            /*---------------End--------------*/

            HttpContext.Current.Response.Write("</table>");
            HttpContext.Current.Response.Write("</body>");
            HttpContext.Current.Response.Write("</html>");
        }

        public static void ExportExpenditure(string _fileName, string _sheetName, string _titile, string _companyName,
            string _addressName, string _payerRecipientCode, string _addressPayerRecipient, string _reasonRecipient, string _amount, string _amountText,
            string _VoucherAmount, string _date, string _month, string _year)
        {
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + _fileName + ".xls");
            HttpContext.Current.Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
            HttpContext.Current.Response.Write("<head>");
            HttpContext.Current.Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">");
            HttpContext.Current.Response.Write("<!--[if gte mso 9]>");
            HttpContext.Current.Response.Write("<xml>");
            HttpContext.Current.Response.Write("<x:ExcelWorkbook>");
            HttpContext.Current.Response.Write("<x:ExcelWorksheets>");
            HttpContext.Current.Response.Write("<x:ExcelWorksheet>");
            //this line names the worksheet
            HttpContext.Current.Response.Write("<x:Name>" + _sheetName + "</x:Name>"); //Tên Sheet
            HttpContext.Current.Response.Write("<x:WorksheetOptions>");
            //these 2 lines are what works the magic
            HttpContext.Current.Response.Write("<x:Panes>");
            HttpContext.Current.Response.Write("</x:Panes>");
            HttpContext.Current.Response.Write("</x:WorksheetOptions>");
            HttpContext.Current.Response.Write("</x:ExcelWorksheet>");
            HttpContext.Current.Response.Write("</x:ExcelWorksheets>");
            HttpContext.Current.Response.Write("</x:ExcelWorkbook>");
            HttpContext.Current.Response.Write("</xml>");
            HttpContext.Current.Response.Write("<![endif]-->");
            HttpContext.Current.Response.Write("</head>");
            HttpContext.Current.Response.Write("<body>");
            /*--Cấu hình Template--*/
            HttpContext.Current.Response.Write(
                "<table style=\"width: 100%;font-family: Times New Roman;border: 2px solid #000080\">");
            /*---------------Header---------------*/
            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write(
                "<td style='text-align: left;padding: 5px;width: 30%;vertical-align: middle'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Đơn vị : " + _companyName +
                                               " </p>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Địa chỉ : " +
                                               _addressName + " </p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write(
                "<td style='text-align: center;width: 40%;font-family: Times New Roman;font-weight: bold;font-size: 24px;vertical-align: middle'>");
            HttpContext.Current.Response.Write(_titile);
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write(
                "<td style='text-align: left;width: 10%;margin-left: 8px;vertical-align: middle'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Số : </p>");
            HttpContext.Current.Response.Write("</td>");


            HttpContext.Current.Response.Write(
                "<td style='text-align: center;width: 20%;margin-left: 8px;vertical-align: middle'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Mã số : 02 - TT</p>");
            HttpContext.Current.Response.Write(
                "<p style='margin:5px 5px 0 0;font-size: 12px'>(Ban hành theo QĐ số 15/2006/QĐ-BTC)</p>");
            HttpContext.Current.Response.Write(
                " <p style='margin:5px 5px 0 0;font-size: 12px;font-style: italic'>(ngày 20/03/2006 của Bộ Trưởng BTC)</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write("<span>Ngày " + _date + " tháng " + _month + " năm " + _year + "</span><br/>");
            HttpContext.Current.Response.Write("<span>Quyển số : ......</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Nợ : " + _VoucherAmount + " </p>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0;font-weight: bold'>Có : " + _amount + "</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td colspan='4' style='height: 20px'>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");
            /*---------------End---------------*/

            /*--------Nội dung Export---------*/
            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Họ tên người nhận tiền :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _payerRecipientCode + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Địa chỉ :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _addressPayerRecipient + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Lý do chi :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _reasonRecipient + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Số tiền :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px;text-align: left'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _amount + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='padding: 8px;text-align: left'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>Số tiền bằng chử :</p>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td colspan='3' style='padding: 8px'>");
            HttpContext.Current.Response.Write("<p style='margin:5px 5px 0 0'>" + _amountText + "</p>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");
            /*---------------End--------------*/

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td colspan='4' style='height: 20px'>");
            HttpContext.Current.Response.Write("</td>");
            HttpContext.Current.Response.Write("</tr>");

            /*--------------Footer------------*/
            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write("<span style='margin-left: 150px;font-weight: 600'>Giám đốc</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write("<span style='margin-left: 150px;font-weight: 600'>Kế toán trưởng</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write("<span style='margin-left: 150px;font-weight: 600'>Thủ quỹ</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 150px;font-weight: 600'>Người lập phiếu</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("</tr>");

            HttpContext.Current.Response.Write("<tr>");
            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 113px;font-weight: 400;font-style: italic'>(Ký,họ tên,đóng dấu)</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 87px;font-weight: 400;font-style: italic'>(Ký,họ tên,đóng dấu)</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 103px;font-weight: 400;font-style: italic'>(Ký,họ tên,đóng dấu)</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("<td style='text-align: center'>");
            HttpContext.Current.Response.Write(
                "<span style='margin-left: 99px;font-weight: 400;font-style: italic'>(Ký,họ tên,đóng dấu)</span>");
            HttpContext.Current.Response.Write("</td>");

            HttpContext.Current.Response.Write("</tr>");
            /*---------------End--------------*/

            HttpContext.Current.Response.Write("</table>");
            HttpContext.Current.Response.Write("</body>");
            HttpContext.Current.Response.Write("</html>");
        }

        public static void ExportExcelSell(string _fileName, string _sheetName,
            string _titile, string _companyName, string _addressName,
            string _dateTime, string _SellCode, string _CustomerName, string _content,
            string _quanlityProduct, string _price, string _ckPercent, string _vatPercent, string _totalPrice)

    {
        HttpContext.Current.Response.ContentType = "application/ms-excel";
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + _fileName + ".xls");
        HttpContext.Current.Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
        HttpContext.Current.Response.Write("<head>");
        HttpContext.Current.Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">");
        HttpContext.Current.Response.Write("<!--[if gte mso 9]>");
        HttpContext.Current.Response.Write("<xml>");
        HttpContext.Current.Response.Write("<x:ExcelWorkbook>");
        HttpContext.Current.Response.Write("<x:ExcelWorksheets>");
        HttpContext.Current.Response.Write("<x:ExcelWorksheet>");
        //this line names the worksheet
        HttpContext.Current.Response.Write("<x:Name>" + _sheetName + "</x:Name>"); //Tên Sheet
        HttpContext.Current.Response.Write("<x:WorksheetOptions>");
        //these 2 lines are what works the magic
        HttpContext.Current.Response.Write("<x:Panes>");
        HttpContext.Current.Response.Write("</x:Panes>");
        HttpContext.Current.Response.Write("</x:WorksheetOptions>");
        HttpContext.Current.Response.Write("</x:ExcelWorksheet>");
        HttpContext.Current.Response.Write("</x:ExcelWorksheets>");
        HttpContext.Current.Response.Write("</x:ExcelWorkbook>");
        HttpContext.Current.Response.Write("</xml>");
        HttpContext.Current.Response.Write("<![endif]-->");
        HttpContext.Current.Response.Write("</head>");
        HttpContext.Current.Response.Write("<body>");
        /*--Cấu hình Template--*/
        HttpContext.Current.Response.Write("<table style='border: 2px solid #000080;width: 900px'>");
        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write("<td>");

        #region[Template-Header]

        HttpContext.Current.Response.Write(
            "<table border='0' style='width: 100%;font-family: Times New Roman' align='center'>");
        /*---------------Header---------------*/
        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write("<td colspan='9'>");
        HttpContext.Current.Response.Write(" <p style='margin: 5px 5px 0 0;font-size: 12pt;font-weight: bold'>");
        HttpContext.Current.Response.Write(_companyName);
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("</tr>");

        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write("<td colspan='9'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0'>");
        HttpContext.Current.Response.Write(_addressName);
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("</tr>");

        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 35px'></td>");
        HttpContext.Current.Response.Write("</tr>");

        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write(
            "<td colspan='9' style='height: 35px;text-align: center;vertical-align: middle'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0;font-size: 18pt;font-weight: bold'>");
        HttpContext.Current.Response.Write(_titile);
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("</tr>");

        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write("<td style='width: 10%'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;text-align: right'>");
        HttpContext.Current.Response.Write("</td>");

        HttpContext.Current.Response.Write("<td style='width: 10%'></td>");

        HttpContext.Current.Response.Write("<td style='width: 10%;text-align: right'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0;font-size: 12pt;font-weight: bold'>");
        HttpContext.Current.Response.Write("Ngày xuất hoá đơn :");
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");

        HttpContext.Current.Response.Write("<td style='width: 10%;text-align: center'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0;font-size: 12pt;font-style: italic'>");
        HttpContext.Current.Response.Write(_dateTime);
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("<td style='width: 10%'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%'></td>");
        HttpContext.Current.Response.Write("<td style='width: 10%'></td>");
        HttpContext.Current.Response.Write("</tr>");

        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 30px'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0;font-size: 12pt;'>Mã hoá đơn:</p>");
        HttpContext.Current.Response.Write("</td>");

        HttpContext.Current.Response.Write("<td style='width: 10%;'colspan='8'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0;font-size: 12pt;'>");
        HttpContext.Current.Response.Write(_SellCode);
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("</tr>");

        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write("<td style='width: 10%;height: 30px'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0;font-size: 12pt;'>");
        HttpContext.Current.Response.Write(" Tên khách hàng:");
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");

        HttpContext.Current.Response.Write("<td style='width: 10%;height: 30px;'colspan='8'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0;font-size: 12pt;'>");
        HttpContext.Current.Response.Write(_CustomerName);
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("</tr>");
        /*---------------End---------------*/
        HttpContext.Current.Response.Write("</table>");

        #endregion

        /*--------Nội dung Export---------*/
        HttpContext.Current.Response.Write(
            "<table border='0' style='width: 100%;font-family: Times New Roman' align='center'>");
        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write(
            "<td colspan='9' style='height: 35px;text-align: center;vertical-align: middle'>");
        HttpContext.Current.Response.Write("<p style='margin: 5px 5px 0 0;font-size: 16pt;font-weight: bold'>");
        HttpContext.Current.Response.Write("DANH SÁCH HÀNG HOÁ");
        HttpContext.Current.Response.Write("</p>");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("</tr>");

        #region[Template-Header]

        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write(
            @"<td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        STT
                    </td>
                    <td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        Mã hàng hoá
                    </td>
                    <td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        Tên hàng hoá
                    </td>
                    <td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        ĐVT
                    </td>
                    <td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        Số lượng bán
                    </td>
                    <td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        Thành tiền
                    </td>
                    <td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        Chiết khấu
                    </td>
                    <td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        Thuế VAT
                    </td>
                    <td style='width: 10%;font-size: 12pt;text-align: center;font-weight: bold'>
                        Tiền thanh toán
                    </td>");
        HttpContext.Current.Response.Write("</tr>");

        #endregion

        #region[Template-Content]

        HttpContext.Current.Response.Write(_content);

        #endregion

        #region[Template-Total]

        HttpContext.Current.Response.Write("<tr>");
        HttpContext.Current.Response.Write(
            "<td colspan='4' style='width: 10%;font-weight: bold;text-align: center'>");
        HttpContext.Current.Response.Write("TỔNG CỘNG");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;text-align: center;font-size: 12pt'>");
        HttpContext.Current.Response.Write(_quanlityProduct);
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;text-align: center;font-size: 12pt'>");
        HttpContext.Current.Response.Write(_price);
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;text-align: center;font-size: 12pt'>");
        HttpContext.Current.Response.Write(_ckPercent);
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;text-align: center;font-size: 12pt'>");
        HttpContext.Current.Response.Write(_vatPercent);
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("<td style='width: 10%;text-align: center;font-size: 12pt'>");
        HttpContext.Current.Response.Write(_totalPrice);
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("</tr>");

        #endregion

        HttpContext.Current.Response.Write("</table>");

        #region[Template-Footer]

        HttpContext.Current.Response.Write(
            @"<table border='0' style='width: 100%;font-family: Times New Roman' align='center'>
                <tr>
                    <td colspan='9' style='height: 35px;text-align: center;vertical-align: middle'></td>
                </tr>
                <tr>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center;'>
                        <p style='font-size: 12pt;font-style: italic'>
                            Tp.HCM, ngày …. tháng …. Năm …….
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center;'>
                        <p style='font-size: 12pt;font-style: italic'>
                            Tp.HCM, ngày …. tháng …. Năm …….
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center;'>
                        <p style='font-size: 12pt;font-style: italic'>
                            Tp.HCM, ngày …. tháng …. Năm …….
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%'></td>
                </tr>
                <tr>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center'>
                        <p style='font-size: 12pt;font-weight: bold'>
                            Người lập
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center'>
                        <p style='font-size: 12pt;font-weight: bold'>
                            Kế toán trưởng
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center'>
                        <p style='font-size: 12pt;font-weight: bold'>
                            Giám đốc
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%'></td>
                </tr>
                <tr>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center'>
                        <p style='font-size: 12pt;font-style: italic'>
                           (ký, họ tên)
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center'>
                        <p style='font-size: 12pt;font-style: italic'>
                           (ký, họ tên)
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%;text-align: center'>
                        <p style='font-size: 12pt;font-style: italic'>
                           (ký, họ tên)
                        </p>
                    </td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%'></td>
                    <td style='width: 10%'></td>
                </tr>
            </table>");

        #endregion

        HttpContext.Current.Response.Write("</tr>");
        HttpContext.Current.Response.Write("</td>");
        HttpContext.Current.Response.Write("</table>");
        /*---------------End--------------*/
        /*--End--*/
        HttpContext.Current.Response.Write("</body>");
        HttpContext.Current.Response.Write("</html>");
    }
    }
}